{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ce619fea",
   "metadata": {},
   "source": [
    "## 本月学习目标（10.06-10.31）\n",
    "### 1. 列表的基础用法\n",
    "### 2. 列表的高级用法（在列表中使用切片）\n",
    "### 3. 购物车程序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f819779e",
   "metadata": {},
   "source": [
    "###  知识回顾（变量）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ed1af7ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数字对象\n",
    "import random\n",
    "wait_time  = random.randint(1, 60) # 将随机数赋给wait_time变量\n",
    "wait_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "21cf1ac6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'You are my celebrity'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串对象\n",
    "word = \"You are my celebrity\"\n",
    "word"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2a4851c",
   "metadata": {},
   "source": [
    "##### Python 中一切都是变量，所有对象都可以赋给变量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb3b8cbe",
   "metadata": {},
   "source": [
    "### 初步认识4个内置数据结构\n",
    "#### 列表、元组、字典、集合\n",
    "##### 有序集合可变 / 不可变\n",
    "* 列表：有序的可变对象对象集合（列表中的每个元素从0开始编号）\n",
    " * 列表是可变的，可以在任何时间通过增加、删除或修改对象\n",
    " * 列表就像一个数组—它储存的对象顺序放置在槽中\n",
    "* 元组：有序的不可变对象集合\n",
    " * 元组是一个不可变的列表，一旦向一个元组赋对象，任何情况下这个元组都不能再改变。\n",
    " * 元组可以确保你的对象不被你的（或其他人的）代码修改\n",
    "---\n",
    "##### 无序数据结构\n",
    "* 字典：无序的键/值对集合（字典是无序且可变的一种数据结构）\n",
    " * 在字典中每个唯一键有一个与之关联的值，字典可以包含多个键/值对。\n",
    " * 与键关联的值可以是任意对象\n",
    "* 集合：无序的唯一对象集合(一种避免重复的数据结构,集合不允许有重复的对象）\n",
    " * 集合可以用来保存相关对象的一个集合，同时确保其中任何对象不会重复\n",
    " * 与列表和字典类似，集合可以根据需要扩展（和收缩）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0e889ac",
   "metadata": {},
   "source": [
    "###  一、列表的基础用法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42a14a5d",
   "metadata": {},
   "source": [
    "#### 1.1 创建字面列表（直接将对象赋给一个新列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ab5cb7a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将[]赋给一个名为prices的变量，来创建一个空列表\n",
    "prices = []\n",
    "# 浮点数列表\n",
    "temps = [23.0, 29.2, 30.2, 25.0]\n",
    "# 字符串列表\n",
    "words = ['Para','Juicy']\n",
    "# 混合类型列表\n",
    "phone_details = ['iPhone', 'ios15', 118.18, 6330]\n",
    "# 包含列表对象的列表\n",
    "everything = [prices, temps, words, phone_details]\n",
    "# 包含字面列表的字面列表例子\n",
    "odds_and_ends = [[1,2,3], ['a','b','c'],['one', 'two', 'three']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed2c1791",
   "metadata": {},
   "source": [
    "#### 1.2 使用列表（用列表实现一个给定的单词是否包含某个元音）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "63ff30ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "u\n",
      "i\n"
     ]
    }
   ],
   "source": [
    "# 先定义一个名为vowels的列表\n",
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "# 需要检查的单词，创建一个变量\n",
    "word = \"Juicy\"\n",
    "# 询问一个对象在另一个对象中吗？用“in”检查\n",
    "for item in word:\n",
    "    if item in vowels:\n",
    "        print(item)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc014e41",
   "metadata": {},
   "source": [
    "#### 1.3 在运行时“扩展”列表\n",
    "*  append() 圆括号的内容是 对象（比较大的一个范围，python中一切皆是对象）\n",
    "*  append() 新增在末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "640dfed3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = []\n",
    "len(vowels) # “len”内置函数会报告一个对象的大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e97d59fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o', 'u', 'e', 'i', 'o', 'a']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 确认vowels列表中没有任何对象后\n",
    "# 使用“append”方法在运行时将对象增加到现有列表\n",
    "vowels.append('a')\n",
    "vowels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2f2e096d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o', 'u', 'e', 'i', 'o', 'a', 'e', 'i', 'o']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels.append('e')\n",
    "vowels.append('i')\n",
    "vowels.append('o')\n",
    "vowels\n",
    "# 随着运行次数的增加，列表对象也会重复增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "620ca246",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "9045aef8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o', 'u', 'e', 'i', 'o', 'a', 'e', 'i', 'o']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断对象在不在“里面”\n",
    "if 'u' not in vowels:\n",
    "    vowels.append('u')\n",
    "vowels\n",
    "# \"u\"已经在’vowels中，所以列表没有继续增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0bc35a0e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 完善代码(练习)\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f6fa5cd",
   "metadata": {},
   "source": [
    "#### 课本代码一"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7b28c765",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: para\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 课本代码（用列表实现用户输入一个单词，将搜索这个单词中的元音）\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "add = []\n",
    "for item in word:\n",
    "    if item in vowels:\n",
    "        if item not in add:\n",
    "            add.append(item)\n",
    "for i in add:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eea820ed",
   "metadata": {},
   "source": [
    "#### 1.4 从列表中删除对象\n",
    "* remove：取一个对象值作为唯一参数\n",
    " * 从列表中删除指定数据值（同时列表大小减一）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "91dad7ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 5, 6, 7]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [1,2,3,4,5,6,7]\n",
    "nums.remove(4) # （）里不是索引值，是要删除的值\n",
    "nums"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47d44372",
   "metadata": {},
   "source": [
    "#### 1.5从列表弹出对象\n",
    "* pop: 取一个可选的索引值作为参数\n",
    " * 根据对象的索引值从现有列表删除和返回一个对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "89dd63f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [1,2,3,4]\n",
    "nums.pop() # 这里没有告诉“pop”要删除哪个对象，所以它会弹出列表中的最后一项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4531f4fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums.pop(0) #(0)是一个索引值，0对应列表中的第一个对象\n",
    "nums"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04539afd",
   "metadata": {},
   "source": [
    "#### 1.6 用对象扩展列表（和append方法一样仅限于在现有列表末尾增加对象）\n",
    "* extend：取一个对象列表作为唯一参数（向列表动态增加数据）\n",
    " * 将各个对象增加到现有列表（例如 将两个列表合并为一个列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b6980f58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[6, 1, 8]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "number = [6] #目前的“number”列表是一个单元素列表\n",
    "number.extend([1,8]) #提供一个对象列表，追加到现有列表\n",
    "number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "684ff5a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[6, 1, 8]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "number.extend([]) #使用“extend（[]）”并没有在列表中增加任何元素\n",
    "number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ad228d43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[6, 1, 8, []]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "number.append([]) #如果调用“append([])”会在现有列表末尾增加一个空列表\n",
    "number"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c7aac30",
   "metadata": {},
   "source": [
    "#### 1.7 在列表中插入一个对象\n",
    "* insert: 取一个索引值和一个对象作为参数\n",
    " * 可以将一个对象插入到现有列表中指定索引值前面\n",
    " * 也可以插入到列表中的任何位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "052d5b62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8, 10]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "no = [2,4,6,8,10]\n",
    "no.insert(0,0) #（0,0）第一个是指要插入对象在这个索引值位置之前，第二个指要插入的值（也就是“对象”）\n",
    "no"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "cae262a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 'You are my celebrity', 6, 8, 10]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "no.insert(3,\"You are my celebrity\") \n",
    "no"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad8f3089",
   "metadata": {},
   "source": [
    "#### 课本代码二"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3504bf15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase) #把字符串转变为list list(str)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "#循环4次，进行4次plist的pop方法操作，即删除4次末位\n",
    "for i in range(4):\n",
    "    plist.pop() #Don't pa (注意：空格算一个字符)\n",
    "plist.pop(0)  #on't pa\n",
    "plist.remove(\"'\") #ont pa\n",
    "plist.extend([plist.pop(),plist.pop()]) #第一个pop弹出“a”，第二个pop弹出“p”；弹出后为extend([a,p]); ont ap\n",
    "plist.insert(2,plist.pop(3))\n",
    "#先弹出第3个对象—空格字符;弹出后为insert(2,空格):在第二个对象（从0开始-t）前加空格；on tap\n",
    "new_phrase = ''.join(plist) # 将列表转换为字符串 ''.join(list)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6fa5a49",
   "metadata": {},
   "source": [
    "### 二、列表的高级用法\n",
    "#### 2.1 赋值操作符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "1fd8f8b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first = [1,2,3,4,5,6]\n",
    "first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "277c85d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second = first\n",
    "second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "db8a536f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 8]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second.append(8)\n",
    "second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "1f2e2b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 8]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first  #通过赋值操作符复制列表会出现一个问题: 如果修改一个列表，另一个也会改变"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54b87d19",
   "metadata": {},
   "source": [
    "#### 2.2 实现真正的复制（copy方法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "09540214",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 8]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "third = second.copy()\n",
    "third"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "edb137da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 8, 9]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "third.append(9)\n",
    "third"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "8ec416a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 8]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second #使用copy()方法复制，新对象“9”只增加到“third”列表中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddc102dc",
   "metadata": {},
   "source": [
    "#### 2.3 中括号的扩展\n",
    "* 正索引值从左向右数，负索引值从右向左数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "01c1aa49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "line = list(phrase)\n",
    "line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "860fa097",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "84635604",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'!'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line[-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c194fd5",
   "metadata": {},
   "source": [
    "#### 2.4 列表中的开始、结束和步长值\n",
    "* START值允许你控制范围从哪里开始\n",
    " * 用于列表时，开始值指示开始索引值\n",
    "* STOP值允许你控制范围何时结束\n",
    " * 用于列表时，结束值指示到哪个索引值结束，但不包括这个索引值\n",
    "* STEP值允许你控制范围如何生成\n",
    " * 用于列表时，步长值指示每一步大小"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c545595",
   "metadata": {},
   "source": [
    "###### 用于列表时，可以把开始、结束和步长值放在中括号里，相互用冒号（：）字符分隔\n",
    "* letters[start:stop:step] #可以指定开始、结束和步长值\n",
    " * 如果没有指定开始值，则默认值为0\n",
    " * 如果没有指定结束值，则取列表允许的最大值\n",
    " * 如果没有指定步长值，则默认值为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "ad6dc91b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C', 'e', 'l', 'e', 'b', 'r', 'i', 't', 'y', '5', '1', '6']"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentence = \"Celebrity516\"\n",
    "letter = list(sentence)\n",
    "letter"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c5e0bb4",
   "metadata": {},
   "source": [
    "#### 2.5 列表切片的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "0a20c3fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['e', 'b', 'r', 'i', 't', 'y', '5', '1', '6']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letter[3:] #跳过前3个字母，然后给出其余所有字母"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "757de4d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C', 'e', 'l', 'e', 'b', 'r', 'i', 't', 'y', '5']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letter[:10] #直到（不包括）索引位置10的所有字母"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "7dab314a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C', 'e', 'i', '5']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letter[0:10:3] #每3个字母选1个，直到索引位置10（不包括10）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c791a7d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C', 'l', 'b', 'i', 'y', '1']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letter[::2] #每2个字母选择1个"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
